home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-13
/
me_cd22.zip
/
MUTT2.ZIP
/
SHELL.MUT
< prev
next >
Wrap
Text File
|
1992-04-27
|
3KB
|
110 lines
;; shell.mut
;; An attempt at a shell buffer using the compute server.
;; Note: the shell is NOT interactive.
;; C Durland 11/91 Public Domain
(include me2.h)
(const
SHELL-BUFFER-NAME "*Shell*"
)
(int shell-buffer shell-process-id output-mark)
(bool shell-running command-running)
(defun
MAIN { (register-hook PROCESS-HOOK "process-shell-hook") }
shell-shock
{
(int wid)
(string command)
(if (shell-running) { (msg "Got a shell already running!")(done) })
(if (== -2 (shell-buffer (attached-buffer SHELL-BUFFER-NAME)))
(shell-buffer (create-buffer SHELL-BUFFER-NAME BFFoo)))
(if (!= -2 (wid (buffer-displayed shell-buffer)))
(current-window wid)
{
(delete-other-windows)(split-window)
(current-window 0) ;; move to top window
})
(current-buffer shell-buffer TRUE) (clear-buffer)
(bind-local-key "shell-ret" "C-M")
(if (== 0 output-mark) (output-mark (create-mark TRUE)))
(command-running FALSE)
(shell-running TRUE)
(major-mode "Waiting")
(insert-text "> ^J")(update)
}
shell-ret
{
(int mark bag col)
(string command)
(beginning-of-line)
; look for cd, pu and po
(mark (create-mark))(set-mark)(end-of-line)
(bag (create-bag))(append-to-bag bag APPEND-REGION)
(forward-line 1)
(if (not (EoB)) { (end-of-buffer)(insert-bag bag)(forward-line 1) })
(set-mark output-mark)
(shell-process-id (create-process
(concat "/bin/sh -c " '"' (bag-to-string bag) '"')))
(if (== -1 shell-process-id) (done)) ;; some kind of error
(major-mode (concat "Running: " (bag-to-string bag)))
(command-running TRUE)
}
process-shell-hook (int pid event-type)(message)
{
(int wid1 wid2)
(if (== PERROR event-type)
{
(if shell-running
{ (current-buffer shell-buffer) (major-mode "Error") (update) })
(shell-running FALSE)
(done)
})
(if (not (shell-running)) (done))
(if (!= shell-process-id pid) (done))
(current-buffer shell-buffer)(goto-mark output-mark)
(switch event-type
PROCESS-DONE
{
(command-running FALSE)
(major-mode (concat "Waiting"))
(insert-text "^J> ^J")
}
OUTPUT-STDOUT { (insert-text message) }
OUTPUT-STDERR { (insert-text message) }
)
(set-mark output-mark)
(update)
}
)
(defun
buffer-displayed (int buffer-id) HIDDEN
{
(int n)
(for (n 0) (< n (windows)) (+= n 1)
(if (== buffer-id (attached-buffer n)) { n (done) }))
-2 ;; buffer not displayed
}
)